<template>
    <el-form :model="ruleForm" :rules="rules" ref="ruleForm" label-width="100px" class="demo-ruleForm">
  <el-form-item label="用户id">
    <el-input v-model="ruleForm.id" readonly></el-input>
  </el-form-item>
  <el-form-item label="用户身份证" prop="identity_id">
    <el-input v-model="ruleForm.identity_id"></el-input>
  </el-form-item>
  <el-form-item label="用户密码" prop="password">
    <el-input v-model="ruleForm.password"></el-input>
  </el-form-item>
   
  <el-form-item>
    <el-button type="primary" @click="submitForm('ruleForm')">修改</el-button>
    <el-button @click="resetForm('ruleForm')">重置</el-button>
  </el-form-item>
</el-form>
</template>
<script>
  export default {
    data() {
      return {
        ruleForm: {
          id: '',
          identity_id: '',
          password: '',
        },
        rules: {
          id: [
            { required: false, message: '请输入用户id', trigger: 'blur' },
            { min: 0, max: 5, message: '长度在 0 到 5 个字符', trigger: 'blur' }
          ],
           identity_id: [
            { required: true, message: '请输入用户身份证', trigger: 'blur' },
            { min: 1, max: 5, message: '长度在  到 5 个字符', trigger: 'blur' }
          ],
          password: [
            { required: true, message: '请输入用户密码', trigger: 'blur' },
            { min: 1, max: 5, message: '长度在 3 到 5 个字符', trigger: 'blur' }
          ],
        
        }
      };
    },
    methods: {
      submitForm(formName) {
          const _this=this
          var qs=require('qs')
        //  _this.$router.push('/notices')
        this.$refs[formName].validate((valid) => {
          if (valid) {
               axios({
            method:"post",
            url:"http://localhost:8088//users/web/update_info_id",
            data:qs.stringify(this.ruleForm),
            headers:
            {
              // "Authorization":"eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJzdWIiOiJ7XCJpZFwiOjksXCJ1c2VybmFtZVwiOm51bGwsXCJwaG9uZVwiOm51bGwsXCJhZGRyZXNzXCI6bnVsbCxcInJlbWFya1wiOm51bGwsXCJhdXRob3JpdHlcIjowLFwicGFzc3dvcmRcIjpcIjExMTExMVwiLFwiaGVhZF9wb3J0cmFpdFwiOm51bGwsXCJhcHBpZFwiOm51bGwsXCJzY29wZVwiOm51bGwsXCJzdGF0ZVwiOm51bGwsXCJ3aGV0aGVyX2RlbGV0ZVwiOm51bGwsXCJpZGVudGl0eV9pZFwiOlwiMTExMTExXCIsXCJjcmVhdGVfdGltZVwiOm51bGwsXCJ1cGRhdGVfdGltZVwiOm51bGwsXCJkZWxldGVfdGltZVwiOm51bGwsXCJvcmRlcnNMaXN0XCI6bnVsbH0iLCJleHAiOjE2MDUwOTU5OTZ9.TBEM_7Ti_Mm_UB9vD236lPstsqMjWAawBaBDFSp6oN0"
            'Authorization':sessionStorage.getItem('token'),
            }
            
        }).then(function (resp){
              if(resp.data.message=='Ok'){
                  _this.$alert('《'+_this.ruleForm.identity_id+'》修改成功！', '消息', {
          confirmButtonText: '确定',
          callback: action => {
               _this.$router.push('/users')
          }  
        });
          }
          
        })
           
           
          }
        });
      },
      resetForm(formName) {
        this.$refs[formName].resetFields();
      }
    },
    created(){
      //alert(this.$route.query)
      alert( this.$route.query.identity_id)
         const _this=this
        axios({
           
            method:"get",
            url:"http://localhost:8088/users/web/selectUserByIdentityId",
            params:{identity_id:this.$route.query.identity_id},
            data:{},
            headers:
            {
              // "Authorization":"eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJzdWIiOiJ7XCJpZFwiOjksXCJ1c2VybmFtZVwiOm51bGwsXCJwaG9uZVwiOm51bGwsXCJhZGRyZXNzXCI6bnVsbCxcInJlbWFya1wiOm51bGwsXCJhdXRob3JpdHlcIjowLFwicGFzc3dvcmRcIjpcIjExMTExMVwiLFwiaGVhZF9wb3J0cmFpdFwiOm51bGwsXCJhcHBpZFwiOm51bGwsXCJzY29wZVwiOm51bGwsXCJzdGF0ZVwiOm51bGwsXCJ3aGV0aGVyX2RlbGV0ZVwiOm51bGwsXCJpZGVudGl0eV9pZFwiOlwiMTExMTExXCIsXCJjcmVhdGVfdGltZVwiOm51bGwsXCJ1cGRhdGVfdGltZVwiOm51bGwsXCJkZWxldGVfdGltZVwiOm51bGwsXCJvcmRlcnNMaXN0XCI6bnVsbH0iLCJleHAiOjE2MDUwOTU5OTZ9.TBEM_7Ti_Mm_UB9vD236lPstsqMjWAawBaBDFSp6oN0"
            'Authorization':sessionStorage.getItem('token'),
            },
            
        }).then(function (resp){
            console.log(resp)
            _this.ruleForm=resp.data.data.users
            
        })
    }
  }
</script>